﻿using AutoMapper;
using Business.ReadAPI.Application.Foods;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.ReadAPI.Application.Immunities
{
    public class ImmunitiesQueryRequestHandler : IRequestHandler<ImmunitiesQueryRequestModel, APIResult>
    {
        private readonly IBaseRepository<Immunity> immunityRepository;
        private readonly IMapper mapper;
        public ImmunitiesQueryRequestHandler(IBaseRepository<Immunity> immunityRepository, IMapper mapper)
        {
            this.immunityRepository = immunityRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(ImmunitiesQueryRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.SearchSuccess;
            result.Msg = "查询成功";

            var list = immunityRepository.GetAll().Where(x=>x.IsDel==false);
            List<ImmunitiesQueryResponseModel> responseModels = mapper.Map<List<ImmunitiesQueryResponseModel>>(list);
            result.Data = responseModels;

            return Task.FromResult(result);
        }
    }
    public class ImmunitiesQueryRequestModel:IRequest<APIResult>
    { 
    }
    public class ImmunitiesQueryResponseModel
    {
        public int Id { get; set; }
        public string ProductCode { get; set; }
        public int FeedingDays { get; set; }
        public string ImmunityType { get; set; }
        public string ImmunityMethod { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
        public bool isShow {  get; set; }
        public bool isAdd { get; set; }
    }
}
